// 获取本地图片
export const getIconPath = (name) => {
	/* #ifdef H5 */
	return new URL(`../static/images/${name}`, import.meta.url).href
	/* #endif */
	
	/* #ifdef APP-PLUS */
	return `static/images/${name}`
	/* #endif */
	

	/* #ifdef MP */ // 微信小程序、支付宝小程序等
	return `/static/images/${name}`
    /* #endif */
}

// 获取定位
export const getLocation = () => {
	return new Promise((resolve, reject) => {
		// uni.getLocation({
		// 	type: 'gcj02',
		// 	altitude: true,
		// 	geocode: true,
		// 	isHighAccuracy: true,
		// 	success: async (res) => {
		// 		// #ifdef H5
		// 		const { regeocode } = await getAddress([res.longitude, res.latitude])
		// 		res.address = {
		// 			address: regeocode.formattedAddress,
		// 			city: regeocode.addressComponent.city,
		// 			street: regeocode.addressComponent.street,
		// 			district: regeocode.addressComponent.district,
		// 			province: regeocode.addressComponent.province,
		// 			streetNum: regeocode.addressComponent.streetNumber,
		// 		}
		// 		// #endif
				
		// 		console.log('定位信息', res);
		// 		resolve(res)
		// 	},
		// 	fail: (err) => {
		// 		reject(err)
		// 	}
		// })
				reject(err)

	})
}

export const getAddress = (lnglat) => {
	return new Promise((resolve, reject) => {
		AMap.plugin("AMap.Geocoder", function () {
			const geocoder = new AMap.Geocoder({})
			geocoder.getAddress(lnglat, function (status, result) {
				if (status === "complete" && result.info === "OK") {
					resolve(result)
				} else {
					reject({ status, result })
				}
			})
		})
	})
}